<?php
class TestController extends ApiController {	
	
	public function actionTemps() {
		$req = new DeliveryTemplatesGetRequest;
		$req->setFields("template_id,template_name,created,modified,supports,assumer,valuation,query_express,query_ems,query_cod,query_post");
		$resp = Yii::app()->top->execute($req, $this->user->top_session);
		print_r($resp);
	}
	
	public function actionUpouterid($page=1) {
		$criteria = new CDbCriteria(array(
			"condition" => "outer_id like '01%'",
			'order'=>'num_iid asc',
			));
		$count = Itmes::model()->count($criteria);
		echo "$count / $page ";
		if((int)$page>$count) die("have no ".$page);
		$pages = new CPagination($count);
		$pageCount = $pages->pageCount;	
		$pages->pageSize = 1;
        $pages->applyLimit($criteria);
		$model = Itmes::model()->find($criteria);
		if(!$model) die("no model");
		echo $model->num_iid.' '.$model->title;
		
		//exit;
		$req = new ItemUpdateRequest;
		$req->setNumIid($model->num_iid);
		$req->setOuterId($model->outer_id);
		$resp = Yii::app()->top->execute($req, $this->user->top_session);
		if($resp->item){
			echo "OK->".$resp->item->num_iid;
			$model->modified = strtotime($resp->item->modified);
			$model->save();
		}else{
			print_r($resp);
		}
	}
	
}
